package com.edisoncgh;

import java.math.BigDecimal;
import java.time.LocalDateTime;

public class Billing {
    long calculateTimeSpan(LocalDateTime startTime,
                           boolean inDayLightSavingOfStartTime,
                           LocalDateTime endTime, boolean inDayLightSavingOfEndTime) {
        java.time.Duration duration = java.time.Duration.between(startTime, endTime);
        if (duration.toMinutes() > 1800) return -1;

        if (inDayLightSavingOfStartTime && inDayLightSavingOfEndTime) {
            return duration.toMinutes();
        } else if (!inDayLightSavingOfStartTime && !inDayLightSavingOfEndTime) {
            return duration.toMinutes();
        } else if (!inDayLightSavingOfStartTime) {
            return duration.toMinutes() - 60;
        } else {
            return duration.toMinutes() + 60;
        }
    }

    BigDecimal calculateFee(long timeLength) {
        if (timeLength < 0) {
            return BigDecimal.valueOf(-1);
        } else if(timeLength <= 20) {
            double fee = timeLength * 0.05;
            return BigDecimal.valueOf(fee);
        } else {
            double fee = 1.0 + (timeLength - 20) * 0.1;
            return BigDecimal.valueOf(fee);
        }
    }
}